<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
	 <script src="./lib/sockjs.js"></script>
    <script src="./lib/stomp.js"></script>
    <script src="./lib/jquery.js"></script>
    <script src="./lib/jquery.mousewheel.js"></script>
    <script src="./dist/kline.js"></script>
</head>
<body>
<div id="kline_container"></div>
</body>
<script type="text/javascript">
    var hrefurl,MainData,StateofTime,CodeData,dataurl,CountDown,hangurl,curprices,SCALE;
    var wsurldata = 'ws://zgxxcl.com:7272/';
    var datashuju = {
            "data": {
                "depths": {
                    "asks": [],
                    "bids": []
                },
                "lines": [],
                "trades": []
            },
            "success": true
       };
    dataurl = "http://zgxxcl.com/home/Ajax/index?pageSize=1000&page=1";
    hangurl = "http://zgxxcl.com/home/ajax/getpro";
    CodeData = GetQueryString('code');
    if(JSON.parse(getCookie("chartSettings"))){
        switch (JSON.parse(getCookie("chartSettings")).charts.period) {
            case 'line':
                StateofTime = 'minute';
                CountDown = 20000;
                SCALE=4;
                break;
            case '1m':
                StateofTime = 'minute';
                CountDown = 20000;
                SCALE=4;
                break;
            case '5m':
                StateofTime = 'minute5';
                CountDown = 200000;
                SCALE=4;
                break;
            case '15m':
                StateofTime = 'minute15';
                CountDown = 800000;
                SCALE=4;
                break;
            case '30m':
                StateofTime = 'minute30';
                CountDown = 1500000;
                SCALE=4;
                break;
            case '1h':
                StateofTime = 'minute60';
                CountDown = 3000000;
                SCALE=4;
                break;
            case '1d':
                StateofTime = 'day';
                SCALE=4;
                // CountDown = 300000000;
                break;
            default:
                StateofTime = 'minute15';
                CountDown = 800000;
                SCALE=4;
                break;
        };
    }else{
         window.location.reload();
    }
    
    hrefurl = "index.html?code="+CodeData;
    // console.log(CountDown)
    $.ajax({
      url: hangurl,
      type: 'get',
      dataType: 'json',
      timeout: 1000,
      success: function (data, status) {
        for (var i = 0; i < data.data.length; i++) {
            if(data.data[i].code==CodeData){
                curprices=data.data[i].price;
            }
        }
      }
    })
	var kline = new Kline({
        element: "#kline_container",
        width: document.body.offsetWidth,
        height: document.body.offsetHeight,
        ranges: [ "1d", "1h", "30m", "15m", "5m", "1m", "line"],
        symbol: CodeData,
        symbolName: CodeData,
        type: "poll", // poll/socket
        url: dataurl+'&goodsType='+StateofTime+'&code='+CodeData,
        limit: 1,
        debug: false,
        reverseColor:false,
        showTrade: false,
    });
    
    

    kline.draw();  //绘制
    kline.pause(); //停止刷新

 if (getCookie("changeBg") == 'night'||!getCookie("changeBg")) {
     setTimeout(function () {
            kline.setTheme('dark'); //设置图表背景为黑色      
     }, 10);
 }else {
      setTimeout(function () {
         kline.setTheme('light');; //设置图表背景为黑色      
     }, 10);
 };

    if (getCookie("language") == 'Chinese') {
        kline.setLanguage('zh-cn'); //设置中文      
    }else {
        kline.setLanguage('en-us');; //设置英文 
    };


    window.onresize = function(){  //视口大小变化时改变K线图大小
        kline.resize(document.body.offsetWidth, document.body.offsetHeight);
    };
    // console.log(JSON.parse(getCookie("chartSettings")))
    function GetQueryString(name){ //截取url
        var reg = new RegExp("(^|&|)" + name + "=([^&?]*)(&|$|)", "i");  
        var r = window.location.search.substr(1).match(reg);  //获取url中"?"符后的字符串并正则匹配
        var context = "";  
        if (r != null)  
            context = r[2];  
            reg = null;  
            r = null;  
            return context == null || context == "" || context == "undefined" ? "" : context;   
    };
    function getCookie(name){  //读取cookie
            var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
            if(arr=document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
    }
    if(StateofTime!='day'){
        window.setInterval(function(){
            kline.resend(); //重新请求数据
            kline.pause(); //停止刷新
        },CountDown);
    }
</script>
</html>
